package main

import (
	"fmt"
)

func checkNum(i int, target chan int) {
	flag := true
	for j := 2; j < i; j++ {
		if i%j == 0 {
			flag = false
		}
	}
	if flag {
		target <- i
	}
}

func readChan(target chan int, flagChan chan bool) {
	for i := range target {
		fmt.Printf("%d,", i)
	}
	flagChan <- true
}

func main() {

	// 1 - 100 素数（只能被1和自己整出的数）

	target := make(chan int)

	flagChan := make(chan bool)

	for i := 2; i < 100; i++ {
		go checkNum(i, target)
		close(target)
	}
	go readChan(target, flagChan)
	for {
		_, ok := <-flagChan
		if ok {
			break
		}
	}
}
